package design2.composite.example2;

public class Demo {
    public static void main(String[] args) {
        Dir dir = new Dir("dir1");
        Dir dir11=new Dir("dir11");
        dir11.fileList.add(new File("file3", 111));
        dir.childDirList.add(dir11);

        dir.fileList.add(new File("file1", 1024));
        dir.fileList.add(new File("file2", 4024));

        print(dir);
    }

    public static void print(Dir dir){
        System.out.println("目录名称：" + dir.name);
        if (null != dir.fileList) {
            dir.fileList.forEach(f->{
                System.out.println("文件名：" + f.name + "    文件大小：" + f.size);
            });
        }
        if (null != dir.childDirList) {
            dir.childDirList.forEach(d->{
                System.out.println("目录名称："+d.name);
                print(d);
            });
        }
    }
}
